/*
* DewPointController.java
* Created on  202015/6/15 16:35
* 版本       修改时间          作者      修改内容
* V1.0.1    202015/6/15       longshihui    初始版本
*
*/

package com.infitecs.eyas.combustion;

import com.infitecs.eyas.combustion.model.CalculateClean;
import com.infitecs.eyas.combustion.model.CalculateDewPoint;
import com.infitecs.eyas.combustion.service.CleanService;
import com.infitecs.eyas.combustion.service.DewPointService;
import com.infitecs.eyas.expression.service.ExpressionService;
import com.infitecs.eyas.power.dao.OperateFieldDao;
import com.infitecs.eyas.power.dao.PowerDao;
import com.infitecs.eyas.power.model.OperateField;
import com.infitecs.eyas.power.model.Power;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import com.infitecs.eyas.step.service.StepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/combustion/dew-point")
public class DewPointController {
    @Autowired
    private DewPointService dewPointService;

    @Autowired
    private SessionService sessionService;

    @Autowired
    private ExpressionService expressionService;
    @Autowired
    private StepService stepService;
    @Autowired
    private OperateFieldDao operateFieldDao;
    @Autowired
    private PowerDao powerDao;
    @Autowired
    private CleanService cleanService;

    @RequestMapping("")
    public String getDewPointPage(HttpServletRequest request) {
        String cId = (String) request.getSession().getAttribute("caseId");
        if (cId == null) {
            return "combustion/dew-point";
        }
        int caseId = Integer.parseInt(cId);
        int step = stepService.getMzFxStep(caseId);
        //判断当前方案流程到哪里
        if (step < 6) {
            request.setAttribute("step", step);
            return "combustion/dew-point";
        }
        step = stepService.geRsStep(caseId);
        if (step < 12) {
            request.setAttribute("step", step);
            return "combustion/dew-point";
        }
        Power powerTitle = powerDao.getCaseById(cId);
        OperateField operateField = operateFieldDao.getOperateField(caseId);
        Map<String, Double> dataMap = cleanService.getCleanDataByCaseId(caseId);
        request.setAttribute("dataMap", dataMap);
        request.setAttribute("powerTitle", powerTitle);
        request.setAttribute("dataMap", dataMap);
        request.setAttribute("caseId", caseId);
        request.setAttribute("operateField", operateField);
        request.setAttribute("message", request.getParameter("message"));
        return "combustion/dew-point";
    }

    @RequestMapping(value = "/saveValueOfDewPointEx", method = {RequestMethod.POST})
    @ResponseBody
    public void saveValueOfDewPointEx(CalculateDewPoint calculateDewPoint) {
        dewPointService.saveValueOfDewPoint(calculateDewPoint);
    }

    @RequestMapping(value = "/getCalculateInit", method = {RequestMethod.POST})
    @ResponseBody
    public void getCalculateInit() {
        sessionService.putDewPointValue(sessionService.getCaseId());
    }

    @RequestMapping(value = "/getCalVo", method = RequestMethod.POST)
    @ResponseBody
    public CalculateDewPoint getCalVo() {
        CalculateDewPoint calculateDewPoint = new CalculateDewPoint();
        calculateDewPoint.setE291(expressionService.calculate(new Param("RE291")));
        calculateDewPoint.setE292(expressionService.calculate(new Param("RE292")));
        calculateDewPoint.setE293(expressionService.calculate(new Param("RE293")));
        calculateDewPoint.setE294(expressionService.calculate(new Param("RE294")));
        calculateDewPoint.setE295(expressionService.calculate(new Param("RE295")));
        calculateDewPoint.setE296(expressionService.calculate(new Param("RE296")));
        calculateDewPoint.setE298(expressionService.calculate(new Param("RE298")));
        calculateDewPoint.setE299(expressionService.calculate(new Param("RE299")));
        calculateDewPoint.setE300(expressionService.calculate(new Param("RE300")));
        calculateDewPoint.setE301(expressionService.calculate(new Param("RE301")));
        calculateDewPoint.setE303(expressionService.calculate(new Param("RE303")));
        dewPointService.saveVo(calculateDewPoint);
        return  calculateDewPoint;
    }
}
